from selenium import webdriver
from time import sleep

driver = webdriver.Chrome()
driver.get("file:///C:/Users/S3214/Downloads/alert.html")
driver.find_element_by_id("alert").click()
# alert切换
alert1 = driver.switch_to.alert
print(alert1.text)  # 获取文本信息
sleep(2)
alert1.accept()     # 弹出框确定
sleep(2)

driver.find_element_by_id("confirm").click()
alert2 = driver.switch_to.alert
print(alert2.text)  # 获取文本信息
sleep(2)
alert2.dismiss()     # 弹出框取消
sleep(2)

driver.find_element_by_id("prompt").click()
alert3 = driver.switch_to.alert
alert3.send_keys("Selenium4")     # 弹出框输入
print(alert3.text)  # 获取文本信息
sleep(2)
alert3.accept()   # 弹出框确定
alert3.dismiss()    # 弹出框取消
sleep(2)
driver.quit()
